﻿using System;

namespace Miao
{
    public readonly struct RangeInt : IRange<int>, IEquatable<RangeInt>
    {
        public int min { get; }
        public int max { get; }

        public RangeInt(int min, int max)
        {
            this.min = min;
            this.max = max;
        }

        public bool Contains(int value)
        {
            return min <= value && value <= max;
        }
        public bool Equals(RangeInt other)
        {
            return min == other.min && max == other.max;
        }

        public override string ToString()
        {
            return $"({min}, {max})";
        }
        public override bool Equals(object obj)
        {
            return obj is RangeInt rangeInt && Equals(rangeInt);
        }
        public override int GetHashCode()
        {
            return HashCode.Combine(min, max);
        }

        public static RangeInt operator /(RangeInt self, int value)
        {
            return new RangeInt(self.min / value, self.max / value);
        }
        public static RangeInt operator *(RangeInt self, int value)
        {
            return new RangeInt(self.min * value, self.max * value);
        }
        public static bool operator ==(RangeInt left, RangeInt right)
        {
            return left.Equals(right);
        }
        public static bool operator !=(RangeInt left, RangeInt right)
        {
            return !(left == right);
        }
    }
}